<?php

class Adept_Binding_Util
{
    
    static public function getPropertyValue($object, $property, $propertyIndex = null) 
    {
        $getter = 'get' . ucfirst($property);
        if (!method_exists($object, $getter)) {
            $getter = 'is' . ucfirst($property);
            if (!method_exists($object, $getter)) {
                if (property_exists($object, $property)) {
                    if (!is_null($propertyIndex)) {
                        return $object->$property[$propertyIndex];
                    } else {
                        return $object->$property;
                    }
                }
                throw new Adept_Exception("Cannot get property value", 0,
                    array('object' => $object,
                        'property' => $property,
                        'propertyIndex' => $propertyIndex));
            }
        }
        if (!is_null($propertyIndex)) {
            return $object->$getter($propertyIndex);
        } else {
            return $object->$getter();
        }        
    }	
    
    static public function setPropertyValue($object, $property, $value, $propertyIndex = null) 
    {
        $setter = 'set' . ucfirst($this->property);

        if (!method_exists($object, $setter)) {
            $property = $this->property;
            if (property_exists($object, $property)) {
                if (!is_null($propertyIndex)) {
                    $object->$property[$propertyIndex] = $value;
                } else {
                    $object->$property = $value;
                }
                return;
            }
            throw new Adept_Exception("Cannot set property", 0,
                array('object' => $object,
                    'property' => $property,
                    'propertyIndex' => $propertyIndex));
        }
        
        if (!is_null($propertyIndex)) {
            $object->$setter($propertyIndex, $value);
        } else {
            $object->$setter($value);
        }    	
    }	
    
}

